package view;

import entity.Color;
import service.ReaderTypeServiceDaoImpl;
import tool.TSUtility;

import java.util.List;

public class ReaderTypeView {
    public static void readerTypeMenu() {
        boolean flag = true;
        while (flag) {
            System.out.println(Color.getAnsiBlue() + Color.getAnsiReset());
            System.out.println("🔣-------~读者类型管理~---------------🔣");
            System.out.println("🐕-------<1.添加读者类型>------------*");
            System.out.println("🐖-------<2.删除读者类型>------------*");
            System.out.println("🐱-------<3.修改读者类型>------------*");
            System.out.println("🐱-------<4.查看读者类型>------------*");
            System.out.println("🐱-------<5.退出>------------*");
            char c = TSUtility.readMenuSelectionPro();
            ReaderTypeServiceDaoImpl readerTypeServiceDao = new ReaderTypeServiceDaoImpl();
            switch (c) {
                case '1':
                    readerTypeServiceDao.insert();
                    break;
                case '2':

                    List judgment = readerTypeServiceDao.judgment();
                    if (judgment.size() == 0) {
                        System.out.println("暂无读者类型，前往添加");
                        break;
                    } else {
                        readerTypeServiceDao.deleteById();
                        break;
                    }

                case '3':
                    List judgment1 = readerTypeServiceDao.judgment();
                    if (judgment1.size() == 0) {
                        System.out.println("暂无读者类型，前往添加");
                        break;
                    } else {
                        readerTypeServiceDao.update();
                        break;
                    }

                case '4':
                    List judgment2 = readerTypeServiceDao.judgment();
                    if (judgment2.size() == 0) {
                        System.out.println("暂无读者类型，前往添加");
                        break;
                    } else {
                        readerTypeServiceDao.getAll();
                        break;
                    }

                case '5':
                    flag = false;
            }
        }
    }

    public static void main(String[] args) {
        readerTypeMenu();
    }
}
